package com.hspedu.list_;

import java.util.ArrayList;
import java.util.List;

/**
 * @author enomix
 * @date 2022-06-15 00:15
 */
public class ListMethod {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("张三丰");
        list.add("贾宝玉");
        System.out.println(list);//[张三丰, 贾宝玉]

        //在index = 1 的位置插入一个对象
        list.add(1,"孙悟空");
        System.out.println(list);//[张三丰, 孙悟空, 贾宝玉]

        List list2 = new ArrayList();
        list2.add("jack");
        list2.add("tom");
        list2.add("tom");
        list.addAll(1, list2);
        System.out.println(list);//[张三丰, jack, tom, 孙悟空, 贾宝玉]

        System.out.println(list.indexOf("tom"));
        System.out.println(list.lastIndexOf("tom"));
        list.remove(0);
        System.out.println(list);
        list.set(1,"玛丽");
        System.out.println(list);

        //List subList(int fromIndex, int toIndex):返回从fromIndex到toIndex位置的子集合
        //返回的子集合 fromIndex <= subList < toIndex 这个范围内
        List returnList = list.subList(0, 2);
        System.out.println("returnList = " + returnList);

    }
}
